<template>
  <div id="app">
    <Topbar :key="topbarKey" />
    <Header />
    <router-view />
    <Footer />
    <!-- 顺序会影响排列层级，为了让登录框不被其他组件遮盖住，所以放后面 -->
    <Login v-show="isShowLoginModel" />
    <!-- <i class="iconfont icon-loading"></i> -->
    <transition name="slide">
      <Toast v-show="isShowToast" />
    </transition>
  </div>
</template>
<script>
import Topbar from "@/components/Topbar.vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import Login from "@/components/Login.vue";
import Toast from "@/components/Toast.vue";
import { JingPinApi } from "@/request/api";
import { mapState } from "vuex";
export default {
  data() {
    return {
      topbarKey: 1,
    };
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  async created() {
    const res = await JingPinApi();
    // console.log("res", res);
  },
  computed: {
    ...mapState({
      isShowLoginModel: (state) => state.showModel.isShowLoginModel,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        // console.log("app-watch");
        this.topbarKey++;
        // console.log(this.topbarKey);
      },
    },
  },
};
</script>
<style lang="less" scoped>
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear; // 进场离场时间
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
